from fastapi import APIRouter, Request
from src.constants.resultcode import ResultCode
from .base import RouterMeta
from src.utils.response import ApiResponse
from src.utils.logger import get_logger
from src.schemas.sticker import AddStickerRequest
from src.service.add_sticker import add_sticker_impl

logger = get_logger("capcut")

router = APIRouter()

@router.post("/add_sticker", name="添加贴纸")
async def add_effect(request: Request, sticker_request: AddStickerRequest):
    """
    添加特效
    """
    try:
        draft_result = add_sticker_impl(
            resource_id=sticker_request.sticker_id,
            start=sticker_request.start,
            end=sticker_request.end,
            draft_id=sticker_request.draft_id,
            transform_y=sticker_request.transform_y,
            transform_x=sticker_request.transform_x,
            alpha=sticker_request.alpha,
            flip_horizontal=sticker_request.flip_horizontal,
            flip_vertical=sticker_request.flip_vertical,
            rotation=sticker_request.rotation,
            scale_x=sticker_request.scale_x,
            scale_y=sticker_request.scale_y,
            track_name=sticker_request.track_name,
            relative_index=sticker_request.relative_index,
            width=sticker_request.width,
            height=sticker_request.height
        )
        return ApiResponse.success(data=draft_result)
    except Exception as e:
        logger.error(f"添加贴纸异常: {str(e)}", exc_info=True)
        return ApiResponse.error(
            result_code=ResultCode.ERROR,
            message=f"添加贴纸失败: {str(e)}"
        )



# 路由元数据配置
meta = RouterMeta(
    router=router,
    prefix="/sticker",
    tags=["贴纸"]
)